package com.example.bookshop.controller.user;

import com.example.bookshop.entity.BaseGoods;
import com.example.bookshop.entity.Cart;
import com.example.bookshop.entity.Goods;
import com.example.bookshop.result.Result;
import com.example.bookshop.service.user.CartService;
import com.example.bookshop.util.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
public class CartController {
    @Autowired
    CartService cartService;
    @RequestMapping("api/getCart")
    public List<BaseGoods> getCart(HttpSession session){
        return cartService.getCart(session);
    }
    @RequestMapping("api/addCart")
    public Result addCart(@RequestBody Cart cart, HttpSession session){
        MyUtil myUtil=new MyUtil();
        cart.setCustomerId(myUtil.getUserId(session));
        return cartService.addCart(cart);
    }
}
